home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / scan.n < prev    next >
Encoding:
Text File  |  1994-12-17  |  5.4 KB  |  141 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) scan.n 1.6 94/12/17 16:18:45
  9. '\" 
  10. .so man.macros
  11. .HS scan tcl
  12. .BS
  13. '\" Note:  do not modify the .SH NAME line immediately below!
  14. .SH NAME
  15. scan \- Parse string using conversion specifiers in the style of sscanf
  16. .SH SYNOPSIS
  17. \fBscan \fIstring format varName \fR?\fIvarName ...\fR?
  18. .BE
  19.  
  20. .SH INTRODUCTION
  21. .PP
  22. This command parses fields from an input string in the same fashion
  23. as the ANSI C \fBsscanf\fR procedure and returns a count of the number
  24. .VS
  25. of conversions performed, or -1 if the end of the input string is
  26. reached before any conversions have been performed.
  27. .VE
  28. \fIString\fR gives the input to be parsed and \fIformat\fR indicates
  29. how to parse it, using \fB%\fR conversion specifiers as in \fBsscanf\fR.
  30. Each \fIvarName\fR gives the name of a variable; when a field is
  31. scanned from \fIstring\fR the result is converted back into a string
  32. and assigned to the corresponding variable.
  33.  
  34. .SH "DETAILS ON SCANNING"
  35. .PP
  36. \fBScan\fR operates by scanning \fIstring\fR and \fIformatString\fR together.
  37. If the next character in \fIformatString\fR is a blank or tab then it
  38. matches any number of white space characters in \fIstring\fR (including
  39. zero).
  40. Otherwise, if it isn't a \fB%\fR character then it 
  41. must match the next character of \fIstring\fR.
  42. When a \fB%\fR is encountered in \fIformatString\fR, it indicates
  43. the start of a conversion specifier.
  44. A conversion specifier contains three fields after the \fB%\fR:
  45. a \fB*\fR, which indicates that the converted value is to be discarded 
  46. instead of assigned to a variable; a number indicating a maximum field
  47. width; and a conversion character.
  48. All of these fields are optional except for the conversion character.
  49. .PP
  50. When \fBscan\fR finds a conversion specifier in \fIformatString\fR, it
  51. first skips any white-space characters in \fIstring\fR.
  52. Then it converts the next input characters according to the 
  53. conversion specifier and stores the result in the variable given
  54. by the next argument to \fBscan\fR.
  55. The following conversion characters are supported:
  56. .TP 10
  57. \fBd\fR
  58. The input field must be a decimal integer.
  59. It is read in and the value is stored in the variable as a decimal string.
  60. .TP 10
  61. \fBo\fR
  62. The input field must be an octal integer. It is read in and the 
  63. value is stored in the variable as a decimal string.
  64. .TP 10
  65. \fBx\fR
  66. The input field must be a hexadecimal integer. It is read in 
  67. and the value is stored in the variable as a decimal string.
  68. .TP 10
  69. \fBc\fR
  70. A single character is read in and its binary value is stored in 
  71. the variable as a decimal string.
  72. Initial white space is not skipped in this case, so the input
  73. field may be a white-space character.
  74. This conversion is different from the ANSI standard in that the
  75. input field always consists of a single character and no field
  76. width may be specified.
  77. .TP 10
  78. \fBs\fR
  79. The input field consists of all the characters up to the next 
  80. white-space character; the characters are copied to the variable.
  81. .TP 10
  82. \fBe\fR or \fBf\fR or \fBg\fR
  83. The input field must be a floating-point number consisting 
  84. of an optional sign, a string of decimal digits possibly con
  85. taining a decimal point, and an optional exponent consisting 
  86. of an \fBe\fR or \fBE\fR followed by an optional sign and a string of 
  87. decimal digits.
  88. It is read in and stored in the variable as a floating-point string.
  89. .TP 10
  90. \fB[\fIchars\fB]
  91. The input field consists of any number of characters in 
  92. \fIchars\fR.
  93. The matching string is stored in the variable.
  94. If the first character between the brackets is a \fB]\fR then
  95. it is treated as part of \fIchars\fR rather than the closing
  96. bracket for the set.
  97. .TP 10
  98. \fB[^\fIchars\fB]
  99. The input field consists of any number of characters not in 
  100. \fIchars\fR.
  101. The matching string is stored in the variable.
  102. If the character immediately following the \fB^\fR is a \fB]\fR then it is 
  103. treated as part of the set rather than the closing bracket for 
  104. the set.
  105. .LP
  106. The number of characters read from the input for a conversion is the
  107. largest number that makes sense for that particular conversion (e.g.
  108. as many decimal digits as possible for \fB%d\fR, as 
  109. many octal digits as possible for \fB%o\fR, and so on).
  110. The input field for a given conversion terminates either when a
  111. white-space character is encountered or when the maximum field 
  112. width has been reached, whichever comes first.
  113. If a \fB*\fR is present in the conversion specifier 
  114. then no variable is assigned and the next scan argument is not consumed.
  115.  
  116. .SH "DIFFERENCES FROM ANSI SSCANF"
  117. .PP
  118. The behavior of the \fBscan\fR command is the same as the behavior of
  119. the ANSI C \fBsscanf\fR procedure except for the following differences:
  120. .IP [1]
  121. .VS
  122. \fB%p\fR and \fB%n\fR conversion specifiers are not currently
  123. supported.
  124. .VE
  125. .IP [2]
  126. For \fB%c\fR conversions a single character value is
  127. converted to a decimal string, which is then assigned to the
  128. corresponding \fIvarName\fR;
  129. no field width may be specified for this conversion.
  130. .IP [3]
  131. .VS
  132. The \fBl\fR, \fBh\fR, and \fBL\fR modifiers are ignored;  integer
  133. values are always converted as if there were no modifier present
  134. and real values are always converted as if the \fBl\fR modifier
  135. were present (i.e. type \fBdouble\fR is used for the internal
  136. representation).
  137. .VE
  138.  
  139. .SH KEYWORDS
  140. conversion specifier, parse, scan
  141.